//
//  StepCell.m
//  趣·美食
//
//  Created by dllo on 15/9/28.
//  Copyright (c) 2015年 金旭. All rights reserved.
//

#import "StepCell.h"


@interface StepCell ()

@property (nonatomic, strong) UILabel *countLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIImageView *stepImage;

@end

@implementation StepCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.countLabel = [[UILabel alloc] init];
        self.countLabel.textColor = [UIColor lightGrayColor];
        [self.contentView addSubview:self.countLabel];
        
        
        self.contentLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.contentLabel];
        self.contentLabel.numberOfLines = 0;
        
        
        self.stepImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.stepImage];

    }
    
    return self;
}



- (void)setStepModel:(GFRecipeStepModel *)stepModel {
    if (_stepModel != stepModel) {

        _stepModel = stepModel;
    }
    
    NSString *str = [NSString stringWithFormat:@"%ld", stepModel.position];
    
    self.countLabel.text = str;
    
    self.contentLabel.text = stepModel.desc;
    
    if ([stepModel.image_url isEqualToString:@""]) {
        
    } else {
        if (stepModel.image_url) {
            [self.stepImage setImageWithURL:[NSURL URLWithString:stepModel.image_url] placeholderImage:[UIImage imageNamed:@"category_1"]];
        }

    }

}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    self.countLabel.frame = CGRectMake(ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 40, ScreenWidth / 375.0 * 30);
    
    if (self.stepModel.image_url == nil) {
        
        CGFloat h = [GFCalculateWidthOrHeigth stringHeight:self.contentLabel.text withWidth:ScreenWidth / 375.0 * 285 withFontDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:17]}];
        
        self.contentLabel.frame = CGRectMake(ScreenWidth / 375.0 * 70, ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 285, h);
        
    } else {
        
        
        CGFloat h = [GFCalculateWidthOrHeigth stringHeight:self.contentLabel.text withWidth:ScreenWidth / 375.0 * 130 withFontDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:17]}];
        
        self.contentLabel.frame = CGRectMake(ScreenWidth / 375.0 * 70, ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 130, h);
        
        self.stepImage.frame = CGRectMake(0, 0, ScreenWidth / 375.0 * 135, ScreenWidth / 375.0 * 110);
        self.stepImage.center = CGPointMake((ScreenWidth / 375.0 * 355 + ScreenWidth / 375.0 * 220) / 2, self.contentView.frame.size.height / 2);
        
    }
    
    

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
